<% @title = "search" %>

<% if @fallback %>
  <div class="errorExplanation">
    <h2>Uh oh...</h2>
    <ul><li>Advanced search is currently unavailable, sorry!</li></ul>
  </div>
<% end %>

<% if @gems %>
  <% @subtitle = t('.subtitle', :query => content_tag(:em, h(params[:query]))) %>

  <% if @exact_match %>
    <header class="gems__header">
      <p class="gems__meter"><%= t '.exact_match' %></p>
    </header>
    <% content_for :head do %>
      <link rel="prerender prefetch" href="<%= rubygem_url(@exact_match) %>">
    <% end %>
    <%= render partial: 'rubygems/rubygem', object: @exact_match %>
  <% end %>

  <header class="gems__header push">
    <p class="gems__meter"><%= page_entries_info(@gems, :entry_name => 'gem', :model => 'gem').html_safe %></p>
  </header>

  <% if suggestions = es_suggestions(@gems)  %>
    <div class='search__suggestions'>
      <p>
        Maybe you mean
        <%= suggestions.map do |term|
          link_to term, search_path(params.except(:controller, :action).merge query: term)
        end.to_sentence(last_word_connector: ' or ').html_safe %>?
      </p>
    </div>
  <% end %>

  <% if @gems.present? %>
    <%= render partial: 'rubygems/rubygem', collection: @gems %>
    <%= will_paginate @gems %>
  <% end %>
<% end %>
